import { defineStore } from "pinia";
import { reqHospitalDetail,reqHospitalDeparment } from '@/api/hospital';
import type { HospitalDetail, HosPitalDetail,DeparmentResponseData } from '@/api/hospital/type'
import type { DetailState } from './interface'
// //pinia仓库写法:组合式API、选择式API写法
const useDetailStore = defineStore('Detail', {
    // 状态
    state: (): DetailState => {
        return {
            hospitalInfo: ({} as HosPitalDetail),
            deparmentArr: []
        }
    },
    // 动作
    actions: {
        async getHospital(hoscode: string) {
            let res: HospitalDetail = await reqHospitalDetail(hoscode)
            if (res.code === 200) this.hospitalInfo = res.data
        },
       async getDeparment(hoscode:string){
        let res: DeparmentResponseData = await reqHospitalDeparment(hoscode)
        if (res.code === 200) this.deparmentArr = res.data
       }
    },
    // 计算
    getters: {}
})

export default useDetailStore